package itheima.com.testlistfragmentdemo.base;

import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by ThinkPad on 2016/11/2.
 */

public abstract class BaseListAdpater<T> extends RecyclerView.Adapter {
    protected List<T>  list=new ArrayList<T>();

    //添加单条数据
    public void addData(T data){
        list.add(data);
        notifyDataSetChanged();;
    }
    //添加集合数据
    public  void setList(List<T> datas){
        list.addAll(datas);
        notifyDataSetChanged();
    }

    public void clear(){
        list.clear();;
        notifyDataSetChanged();
    }

    //取得单条 数据
    public T getData(int position){
        return list.get(position);
    }

    //取得所有集合数据
    public List<T> getList(){
        return list;
    }
    @Override
    public int getItemCount() {
        return list.size();
    }
}
